﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using PPIDesktopClient.General;

namespace PPIDesktopClient.General
{
    public class XMLHelperUploadImage : XMLHelperDownloadImage
    {
        protected XmlNode m_CurrentNode = null;

        public XMLHelperUploadImage(string m_Filename)
            : base(m_Filename)
        {
       
        }

        //protected override XmlNode CreateImageNode(int structureID, string fullName, string name)
        //{
        //    XmlNode ImageNode = m_XmlDocument.CreateElement("Image");
        //    XmlAttribute ImageAtrribute = m_XmlDocument.CreateAttribute("ServerID").Value = "0";
        //    ImageNode.Attributes.Append(ImageAtrribute);
        //    ImageAtrribute = m_XmlDocument.CreateAttribute("Uploaded").Value = false.ToString();
        //    ImageNode.Attributes.Append(ImageAtrribute);
        //    ImageAtrribute = m_XmlDocument.CreateAttribute("StructureID").Value = structureID.ToString();
        //    ImageNode.Attributes.Append(ImageAtrribute);
        //    XmlNode _ChildNode = m_XmlDocument.CloneNode("FullPath");
        //    _ChildNode.AppendChild(m_XmlDocument.CreateTextNode(fullName));
        //    ImageNode.AppendChild(_ChildNode);
        //    _ChildNode = m_XmlDocument.CloneNode("Name");
        //    _ChildNode.AppendChild(m_XmlDocument.CreateTextNode(name));
        //    ImageNode.AppendChild(_ChildNode);
        //    _ChildNode = m_XmlDocument.CloneNode("DateUploaded");
        //    _ChildNode.AppendChild(m_XmlDocument.CreateTextNode(""));
        //    ImageNode.AppendChild(_ChildNode);
        //}

        //public override void AddImageNode(int structureID, string fullName, string name)
        //{
        //    XmlNode ImageNode = CreateImageNode(structureID, fullName, name);
        //    m_XmlDocument.ChildNodes[1].AppendChild(ImageNode);
            
        //}

        public void UpdateNode(int serverID)
        {
            if(m_CurrentNode != null)
            {
                m_CurrentNode.Attributes["Uploaded"].Value = true.ToString();
                m_CurrentNode.Attributes["StructureID"].Value = serverID.ToString();
                m_CurrentNode["DateUploaded"].Value = DateTime.Now.ToString();
                Save();
            }
        }

        public string getNextImage()
        {
            m_CurrentNode = m_XmlDocument.SelectSingleNode(@"//Image[Uploaded='" + false.ToString() + "']");
            return m_CurrentNode["FullPath"].Value;
        }

        

    }
}
